package com.anlen.project.web;
import com.anlen.project.core.Result;
import com.anlen.project.core.ResultGenerator;
import com.anlen.project.model.TUserDevice;
import com.anlen.project.service.TUserDeviceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2017/07/04.
*/
@RestController
@RequestMapping("/t/user/device")
public class TUserDeviceController {
    @Resource
    private TUserDeviceService tUserDeviceService;

    @PostMapping("/add")
    public Result add(TUserDevice tUserDevice) {
        tUserDeviceService.save(tUserDevice);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(Integer id) {
        tUserDeviceService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(TUserDevice tUserDevice) {
        tUserDeviceService.update(tUserDevice);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(Integer id) {
        TUserDevice tUserDevice = tUserDeviceService.findById(id);
        return ResultGenerator.genSuccessResult(tUserDevice);
    }

    @PostMapping("/list")
    public Result list(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<TUserDevice> list = tUserDeviceService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
